package com.kd.controller;

import com.kd.common.E_UserLoginToken;
import com.kd.dao.OrderStatsMapper;
import com.kd.service.order.OrderStatsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController

@RequestMapping("orderstats")
public class OrderStatsController {

    private final OrderStatsService orderStatsService;



    public OrderStatsController(OrderStatsService orderStatsService) {
        this.orderStatsService = orderStatsService;
    }


    // 数据查询接口
    @GetMapping("/daily")
    @E_UserLoginToken
    public List<OrderStatsMapper.DailyStats> getDailyStats(
            @RequestParam(required = false) String month,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyyMM") Map<String, String> params) {

        String finalMonth = month != null ? month : params.get("month");
        return orderStatsService.getDailyStats(finalMonth);
    }

    @GetMapping("/monthly")
    @E_UserLoginToken
    public List<OrderStatsMapper.MonthlyStats> getMonthlyStats(
            @RequestParam String year) { // 格式: yyyy
        return orderStatsService.getMonthlyStats(year);
    }

    @GetMapping("/annual")
    @E_UserLoginToken
    public List<OrderStatsMapper.AnnualStats> getAnnualStats(
            @RequestParam String startYear,
            @RequestParam String endYear) {
        return orderStatsService.getAnnualStats(startYear,endYear);
    }


}